/**
 * 功能描述 列表
 */

define(function (require, exports, module){
	var Grid = require("grid");
	var aw = require("ajaxwrapper");
	var Dialog = require("dialog");
	var store =require("store");
	var Form = require("form");
	
	var instance = {
		initComponent:function (params,widget){
			var grid = new Grid({
				parentNode:".J-grid",
				autoRender: false,
				model:{
					url : "api/checkoutsettlement/querysettlement",
            		params: function () {
                        var subnav = widget.get("subnav");
                        return {
                        	"pkServicePoint":subnav.getValue("servicepoint"),
                    		"status":subnav.getValue("CheckInStatus"),
                    		"checkOutDate":subnav.getValue("checkOutDate").start,
                    		"checkOutDateEnd":subnav.getValue("checkOutDate").end,
                    		"paymentMethod":subnav.getValue("paymentMethod"),
                        };
                    },
					columns:[{
						name: "name",
						label: "目的地",
					},{
						name: "checkInDate",
						label: "入住日期",
						format: "date",
						formatparams: {
							mode: "YYYY.MM.DD"
						}
					},{
						name: "checkOutDate",
						label: "退房日期",
						format: "date",
						formatparams: {
							mode: "YYYY.MM.DD"
						}
					},{
						name: "type",
						label: "入住类型",
					},{
						name: "planItem",
						label: "组团单位",
					},{
						name: "balance",
						label: "结算金额",
						format:function(data, row){
							if(data=="" || data==null){
								return 0;
							}
							return data.toFixed(2);
						}
					},{
        				name : "paymentMethods",
        				label : "结算方式",
        				format : function(value, row){
        					var str = "";
        					for(var i = 0; i < row.paymentMethods.length; i++){
        						if(i == 0){
        							str = row.paymentMethods[i].value;
        						}else{
        							str += "," + row.paymentMethods[i].value
        						}
        					}
        					return str;
        				}
					},{
        				name:"isSales",
        				label : "是否销账",
        				format :function(value, row){
        					if(row.isSales == null){
        						return "";
        					}else if(row.isSales){
        						return "已销账";
        					}else{
        						return "未销账";
        					}
        					return parseFloat(value).toFixed(2);
        				}
        			},{
						name: "confirmStatus",
						label: "状态",
						format : function(data, row){
							if(row.confirmStatus == "NoConfirm"){
								return "待确认";
							}else{
								return "已确认";
							}
						}
					},{
						name: "confirmDate",
						label: "确认日期",
						format: "date",
						formatparams: {
							mode: "YYYY.MM.DD"
						}
					},{
						name:"show",
						label:"操作",
						format:"button",
						formatparams:[{
							id:"edit",
							icon:"icon-edit",
							text:"确认",
							handler:function(index,data,rowEle){
								if(data.isSales == false){
									Dialog.alert({
				                		title:"提示",
				                		content:"该团还未销账！"
				                	});
									return false;
								}
								if(data.confirmStatus == "Confirm"){
									Dialog.alert({
				                		title:"提示",
				                		content:"该状态下，不能再确认了！"
				                	});
									return false;
								}else{
									widget.pcshandler.grid.handleEditClick(widget, data);
								}
							}
						},{
							id:"show",
							text:"查看",
							handler:function(index,data,rowEle){
								//if(data.confirmStatus == "Confirm"){
									//widget.pcshandler.grid.handleShowClick(widget, data,true);
									widget.pcshandler.grid.handlerDetailClick(widget,data);
	        						widget.detail = true;
								/*}else{
									Dialog.alert({
				                		title:"提示",
				                		content:"该状态下，不能查看！"
				                	});
									return false;
								}*/
							}
						},{
        					id:"sales",
        					text:"销账",
        					show: function(value,data){
        						if(data.isSales == false){
        							return true;
        						}else{
        							return false;
        						}
        					},
        					handler:function(index,data,rowEle){
        						aw.ajax({
        							url : "api/checkinimplement/changeoncredit",
        							data : {
        								pkCIImplement : data.pk,
        								isSales : true,
        								//money : data.checkInImplement.onCreditMoney + data.money,
        								fetchProperties : "*"
        							},
        							dataType : "json",
        							success : function(datas){
        								widget.get("grid").refresh();
        							}
        						})
        					}
        				}]
					}]
				}
			});
			widget.set("grid",grid);
		}
	};
	module.exports = instance;
});
